package com.example.weight.arrayAdapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.example.weight.R;

import java.util.List;

public class MyAdapter extends BaseAdapter implements SpinnerAdapter {
    private Context context ;
    private List<String> list;

    public MyAdapter(Context context,List<String> list){
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        //返回数据的统计数量，大于0项则减去1项，从而不显示最后一项
        int i = list.size();
        return i>1?i-1:i;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint({"ViewHolder", "InflateParams"})
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.adapter_item_without_close, null);
        TextView tvgetView = convertView.findViewById(R.id.item_without_close_name);
        tvgetView.setText(getItem(position).toString());
        return convertView;
    }
}